<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="BROWSER_LINKABLE_ITEMS_COLLECTION_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="BROWSER_LINKABLE_ITEMS_GRID" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" scope="page" var="HTML_INPUT_TAG_ID_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="GRID_PAGE_SIZE" />
<atleap:constants className="org.apache.struts.Globals" var="LOCALE_KEY" />
<c:set var="language" value="${sessionScope[pageScope.LOCALE_KEY].language}" />
<atleap:globalProperty name="${pageScope.GRID_PAGE_SIZE}" defaultValue="10" type="integer" var="pageSize" />
<c:set var="inputId" value="${sessionScope[pageScope.HTML_INPUT_TAG_ID_KEY]}" />
<atleap:grid name="${pageScope.BROWSER_LINKABLE_ITEMS_GRID}" pageSize="${pageSize}">
    <table border="0" cellpadding="0" cellspacing="0" class="grid">
        <thead>
            <tr>
                <th nowrap="nowrap">
                    <atleap:column fieldName="title.simpleValue" fieldKey="core.page.form.title">
                        <atleap:sort property="title(${language})">
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                            </atleap:sort>
                        <atleap:stringFilter>
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                         </atleap:stringFilter>
                    </atleap:column>
                </th>
                <th>
                    <atleap:column fieldName="page.className" fieldKey="core.linkableItem.form.class">
                        <atleap:message key="${fieldKey}" />
                        <atleap:setFilter beanId="lookupManager" method="listLinkableItemsClassNames" value="className" label="simpleClassName">
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                         </atleap:setFilter>
                    </atleap:column>
                </th>
                <th>
                    <atleap:column fieldName="role.name" fieldKey="core.linkableItem.form.role">
                        <atleap:message key="core.linkableItem.form.roles" />
                        <atleap:setFilter beanId="lookupManager" method="listRolesAssignedToLinkableItems" value="name" label="title">
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                         </atleap:setFilter>
                    </atleap:column>
                </th>
                <th>
                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  />
                </th>
            </tr>
        </thead>
        <tbody>
            <atleap:rowsIterator var="linkableItem" collection="${requestScope[pageScope.BROWSER_LINKABLE_ITEMS_COLLECTION_KEY]}" oddClass="oddRow" evenClass="evenRow">
                <c:choose>
                    <c:when test="${empty inputId}">
                        <c:set var="onclickFunction" value="if (whetherNeedToRedirect(event, this)) { sendUrl(&#039;${linkableItem.uri}&#039;); return false; }" />
                    </c:when>
                    <c:otherwise>
                        <c:set var="onclickFunction" value="if (whetherNeedToRedirect(event, this)) { sendUrl(&#039;${linkableItem.uri}&#039;, &#039;${inputId}&#039;); return false; }" />
                    </c:otherwise>
                </c:choose>
                <tr class="${rowClass}" onclick="${onclickFunction}">
                    <td>
                        <atleap:fieldValue valueMap="${linkableItem.title}" />
					</td>
                    <td>
                        <c:out value="${linkableItem.simpleClassName}" escapeXml="true" />
					</td>
					<td>
						<c:out value="${linkableItem.rolesAsString}" escapeXml="true" />
					</td>
                    <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                        <a href="javascript:void(0)" onclick="${onclickFunction}" title="<atleap:message key="core.commons.buttons.select" />">
                            <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/select.gif" />" border="0" title="<atleap:message key="core.commons.buttons.select" />" />
                        </a>
                    </td>
                </tr>
            </atleap:rowsIterator>
            <atleap:noRows>
                <tr>
                    <td class="tfoot" colspan="4" align="center">
                        <em><atleap:message key="core.commons.nothingToShow"/></em>
                    </td>
                </tr>
        </atleap:noRows>
        </tbody>
        <tfoot>
            <tr>
                <atleap:pager pageCount="10">
                    <td colspan="4" align="center">
                       <atleap:message key="core.grid.pager.title" />&nbsp;
                       <atleap:firstPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                       <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                       <atleap:pagesIterator>
                           <atleap:page>${pageNumber}&nbsp;</atleap:page>
                           <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                       </atleap:pagesIterator>
                       <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                       <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                    </td>
                </atleap:pager>
            </tr>
        </tfoot>
    </table>
</atleap:grid>
